﻿
@{
    ViewData["Title"] = "Index";
    //Layout = "~/wwwroot/_LayoutManage.cshtml";
}
<div class="">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend>登录</legend>
    </fieldset>
    <div class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required|username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" lay-verify="required|password" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn login" lay-submit=""  lay-filter="demo1">登录</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</div>
<link href="~/Layui/css/layui.css" rel="stylesheet" />
<script src="~/Layui/layui.js"></script>
<script src="~/vue/vue.js"></script>
<script>
    layui.use(['form',"jquery"], function () {
        //debugger;
        var form = layui.form
            , layer = layui.layer,
            $ = layui.jquery;
        //自定义验证规则
        form.verify({
            username: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , password: [/(.+){6,12}$/, '密码必须6到12位']

        });

        //监听提交
        form.on('submit(demo1)', function (data) {
     
            $.ajax({
            type: "post",
            url: '@Url.Action("login")',
            data: data.field,
            //data: { username: $("input[name='username']").val(), password:$("input[name='password']").val() },
                success: function (data) {
                    if (data == "false") {
                        layer.alert("用户名或密码输入错误！")
                    } else {
                        window.location.href = "/Home/index";
                    }
                }, error: function (data) {
                    console.log(data.status);
                }
                })
        });
    });


</script>
